import config
# -*- coding: utf-8 -*-

from load_map import *
from graph import *

class Map:
    def __init__(self, src):
        self.data = load_map(src)
        self.layers =[]

        name = config.config['tilesets']+self.data['tilesets'][0]['image']
        tiles = self.data['tilesets'][0]['tile_size']
        self.tileset = cut_tileset(name, tiles)

        self.create_map()
        print self.layers

    def create_map(self):
        for i in range(len(self.data['layers'])):
            layer = self.data['layers'][i]['data']
            sp_layer = []
            for f in range(len(layer)):
                fil = []
                for c in range(len(layer[0])):
                    fil.append(self.tileset[layer[f][c]])
                sp_layer.append(fil)
            self.layers.append(sp_layer)

    def draw(self, screen):
        for i in range(len(self.layers)):
            for f in range(self.data['size'][1]):
                for c in range(self.data['size'][0]):
                    px = (c-f)*(self.data['tile_size'][0]/2)
                    py = (c+f)*(self.data['tile_size'][1]/2)
                    if self.layers[i][f][c] != None:
                        screen.blit(self.layers[i][f][c], (640+px, py))

def main():
    return 0


if __name__ == '__main__':
    main()